$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/activeuser/list',
        datatype: "json",
        colModel: [			
			{ label: '用户ID', name: 'id', index: "id", width: 45, key: true, hidden:true},
			{ label: '用户名', name: 'attributes.user.primaryPrincipal.username', width: 75 },
            { label: '昵称', name: 'attributes.user.primaryPrincipal.nickName', width: 75 },
            { label: '登陆IP', name: 'host', width: 75 },
			{ label: '邮箱', name: 'attributes.user.primaryPrincipal.email', width: 90 },
			{ label: '手机号', name: 'attributes.user.primaryPrincipal.mobile', width: 100 },
			{ label: '状态', name: 'attributes.user.primaryPrincipal.status', width: 60, formatter: function(value, options, row){
				return value === 0 ? 
					'<span class="label label-danger">禁用</span>' : 
					'<span class="label label-success">正常</span>';
			}},
			{ label: '最近操作时间', name: 'lastAccessTime', index: "lastAccessTime", width: 85}
        ],
		viewrecords: true,
        height: 365,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});
var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "deptId",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    }
};
var ztree;

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            username: null
        },
        showList: true,
        title:null,
        roleList:{},
        user:{
            status:1,
            deptId:null,
            deptName:null,
            roleIdList:[]
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        del: function () {
            var id = getSelectedRows();
            if(id == null){
                return ;
            }

            confirm('确定要剔出选中的登陆用户？', function(){
                $.ajax({
                    type: "GET",
                    url: baseURL + "sys/activeuser/delete?"+"sessionId="+id,
                    contentType: "application/json",
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'username': vm.q.username},
                page:page
            }).trigger("reloadGrid");
        }
    }
});